var app = getApp()

Page({

  data: {
    longitude: "",
    latitude: "",
    markers:[],
    controls:[{
      iconPath:'/resources/pin.png',
      position:{
        left:(app.globalData.windowWidth/2)-11,
        top: ((app.globalData.windowHeight-40) / 2) - 26,
        width:22,
        height:26
      }
    },
      {
        id: 1,
        iconPath: '/resources/center.png',
        position: {
          left: 20,
          top: app.globalData.windowHeight-80,
          width: 30,
          height: 30
        },
        clickable: true
      }]
  },
 
  onShow() {
   // console.log("page");
    this.getLoacation();
    this.getMessages();
  },

  onReady(){
    this.mapCtx=wx.createMapContext("map")
  },
  getMessages(){
    wx.request({
      url: 'https://nuanwan.wekeji.cn/student/index.php/trade/get_LIST',
      data: {
         distinct: "longxiaozhai_cource"
         },
      hander: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: this.getMessagesSucc.bind(this)
    })
  },
  getMessagesSucc(res){
    console.log(res)
    const markers = res.data.data.map((value,index)=>{
      return {
        iconPath:"/resources/" + value.tupe + ".png",
        id: value.id,
        latitude: value.latitude,
        longitude: value.longitude,
        width: 40,
        height: 40
      }
    })
    this.detData({
      markers: markers
    })
  },
  getLoacation() {
    wx.getLocation({
      type: 'gcj02',
      success:this.handleGetLocationSucc.bind(this),
    })
  },
  handleGetLocationSucc(res){
    this.setData({
      longitude: res.longitude,
      latitude: res.latitude
    })
    // console.log(res);
  },
  controltap(){
this.mapCtx.moveToLocation();
  },
  onShareAppMessage() {
    return {
      title: "萌宠交易平台",
      path: '/pages/index/index'
    }
  },
  handleMarherTap(e){
    wx.navigateTo({
      url: '/pages/detail/detail?id='+e.markerId,
    })
  }
})